//
// Created by zeng on 2021/10/17.
//

#include "pushplsh.h"

httplib::Client pushplus::cli{"https://pushplus.hxtrip.com"};
httplib::Headers pushplus::headers = {
        {"Content-Type", "application/json"}
};

pushplus::pushplus(std::string token) : token{token} {
    cli.set_follow_location(true);
}

int pushplus::sendText(json data) {
    httplib::MultipartFormDataItems send{
            {"token",    this->token},
            {"title",    data["title"]},
            {"content",  data["content"]},
            {"template", "json"},
    };
//    send.push_back(data);
//    for (auto i: data) {
//        std::cout<<i;
//        send.push_back(i);
//    }
    auto res = cli.Post("/send", send);
    return res->status;
//    std::cout << res->body;
}